﻿using MediatR;
using Tb.App.API.Applications.Command.Cultivation;
using Tb.App.Domain.Rabbit.Cultivation;
using Tb.App.ErrorCode;
using Tb.App.Infrastructure.Interfaces;

namespace Tb.App.API.Applications.CommandHandler.Cultivation
{
    /// <summary>
    /// 添加免疫信息-命令
    /// </summary>
    public class AddImmunityCommonHandler : IRequestHandler<AddImmunityCommon, ApiResult<int>>
    {
        private readonly IBaseRepository<ImmunityModel> immunityRep;

        public AddImmunityCommonHandler(IBaseRepository<ImmunityModel> immunityRep)
        {
            this.immunityRep = immunityRep;
        }
        public async Task<ApiResult<int>> Handle(AddImmunityCommon request, CancellationToken cancellationToken)
        {
            ApiResult<int> result = new ApiResult<int>();
            result.Code=ApiEnum.添加成功;
            result.Message=ApiEnum.添加成功.ToString();
            
            var entity=await immunityRep.AddRange(request.ImmunityModels);
            
            result.Data = entity;
            return await Task.FromResult(result);
        }
    }
}
